package gemini.castor.ui.client.page.content.customer.customerlist.widget;

import gemini.basic.model.Customer;

import com.google.gwt.event.shared.GwtEvent;

/**
 * The event collections of internal widget for screen uk 1-21.010-a
 */
public class CustomerTableEvent extends GwtEvent<CustomerTableHandler> {

	private static Type<CustomerTableHandler> TYPE;

	public static Type<CustomerTableHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<CustomerTableHandler>();
		return TYPE;
	}
	
	private Customer customer;
	
	public enum EventType {
		EDIT, DELETE, ADD
	}
	
	private EventType eventType;
	
	public CustomerTableEvent(){
		this.eventType = EventType.ADD;
	}
	
	public CustomerTableEvent(EventType eventType, Customer customer){
		this.customer = customer;
		this.eventType = eventType;
	}

	@Override
	protected void dispatch(CustomerTableHandler handler) {
		if(eventType.equals(EventType.ADD)){
		handler.onAdd(this);
		} else if(eventType.equals(EventType.DELETE)){
		handler.onDelete(this);
		} else if(eventType.equals(EventType.EDIT)){
		handler.onEdit(this);
		}
	}

	@Override
	public Type<CustomerTableHandler> getAssociatedType() {
		return getType();
	}
	
	public Customer getCustomer() {
		return customer;
	}
}
